package helipay.api.dao.impl;

import helipay.api.dao.OrdersDao;
import helipay.api.jdbc.StatementParameter;
import helipay.api.model.Orders;
import helipay.api.model.OrdersSwipeCard;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * Created by yimi on 2017/5/31.
 */
@Repository
public class OrdersDaoImpl extends AbstractBaseDao<Orders> implements OrdersDao{

    @Override
    public List<Orders> getOrdersListByAppType(String customerNumber, String appType, String startDate, String endDate, Integer index) {

        StringBuffer sb = new StringBuffer();
        sb.append("SELECT ORDER_AMOUNT, GOODS_NAME,SERIAL_NUMBER,ORDER_ID,CREATED_TIME,STATUS " +
                "FROM ORDERS  WHERE CUSTOMER_NUMBER=? AND APP_TYPE =?  AND CREATED_TIME BETWEEN ? AND ? LIMIT ?,10");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        param.setString(appType);
        param.setString(startDate);
        param.setString(endDate);
        param.setInt(index*10);
        return this.queryForList(sb.toString(),Orders.class,param);
    }


    @Override
    public Integer getSize(String customerNumber, String appType, String startDate, String endDate) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT COUNT(ID) " +
                "FROM ORDERS  WHERE CUSTOMER_NUMBER=? AND APP_TYPE =?  AND CREATED_TIME BETWEEN ? AND ?");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        param.setString(appType);
        param.setString(startDate);
        param.setString(endDate);
        return this.queryForInt(sb.toString(),param);
    }

    @Override
    public List<Orders> orderListByCustomerNumber(String customerNumber) {
        StringBuffer sb = new StringBuffer();
        sb.append("SELECT ORDER_AMOUNT, GOODS_NAME,SERIAL_NUMBER,ORDER_ID,CREATED_TIME,STATUS,APP_TYPE " +
                "FROM ORDERS  WHERE CUSTOMER_NUMBER=?");

        StatementParameter param = new StatementParameter();
        param.setString(customerNumber);
        return this.queryForList(sb.toString(),Orders.class,param);
    }
}
